﻿<!-- Copyright (c) Christof Senn. All rights reserved. See license.txt in the project root for license information. -->
<UserControl x:Class="ActiveFileBackupManager.View.DirectorySelectionView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid.Resources>
            <Color x:Key="GlyphColor">Green</Color>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#88444444" />
        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="3*" MinWidth="100" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="2*" MinWidth="200" />
        </Grid.ColumnDefinitions>

        <TreeView 
            Grid.Column="0"
            ItemsSource="{Binding Directories}"
            BorderBrush="AliceBlue" BorderThickness="1">
            <TreeView.ItemContainerStyle>
                <Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource {x:Type TreeViewItem}}">
                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                    <Setter Property="KeyboardNavigation.AcceptsReturn" Value="True" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding IsAccessForbidden}" Value="True">
                            <Setter Property="Foreground" Value="Red" />
                            <Setter Property="Opacity" Value="0.3" />
                            <Setter Property="ToolTip" Value="Access forbidden" />
                            <Setter Property="IsEnabled" Value="False" />
                            <Setter Property="ToolTipService.ShowOnDisabled" Value="True" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding IsRecursive, Mode=OneWay}" Value="True">
                            <Setter Property="ToolTip" Value="All subfolders included" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </TreeView.ItemContainerStyle>
            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Children, Mode=OneTime}">
                    <StackPanel Orientation="Horizontal">
                        <CheckBox Focusable="False" IsChecked="{Binding IsSelected, Mode=TwoWay}" VerticalAlignment="Center">
                            <CheckBox.Style>
                                <Style TargetType="{x:Type CheckBox}" BasedOn="{StaticResource {x:Type CheckBox}}">
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding IsRecursive, Mode=OneWay}" Value="True">
                                            <Setter Property="Background" Value="LightBlue" />
                                        </DataTrigger>
                                        <MultiDataTrigger>
                                            <MultiDataTrigger.Conditions>
                                                <Condition Binding="{Binding IsSelected, Mode=OneWay}" Value="False" />
                                                <Condition Binding="{Binding IsChildSelected, Mode=OneWay}" Value="True" />
                                            </MultiDataTrigger.Conditions>
                                            <Setter Property="Template">
                                                <Setter.Value>
                                                    <ControlTemplate TargetType="{x:Type CheckBox}">
                                                        <BulletDecorator Background="Transparent">
                                                            <BulletDecorator.Bullet>
                                                                <Border Width="13" Height="13" CornerRadius="0" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}">
                                                                    <Rectangle Stroke="Transparent" Width="5" Height="5">
                                                                        <Rectangle.Fill>
                                                                            <SolidColorBrush Color="{DynamicResource GlyphColor}" />
                                                                        </Rectangle.Fill>
                                                                    </Rectangle>
                                                                </Border>
                                                            </BulletDecorator.Bullet>
                                                            <ContentPresenter Margin="4,0,0,0"
                                                                VerticalAlignment="Center"
                                                                HorizontalAlignment="Left"
                                                                RecognizesAccessKey="True" />
                                                        </BulletDecorator>
                                                    </ControlTemplate>
                                                </Setter.Value>
                                            </Setter>

                                        </MultiDataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </CheckBox.Style>
                        </CheckBox>
                        <ContentPresenter Content="{Binding Directory.Name, Mode=OneTime}" Margin="2,0" />
                    </StackPanel>
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>

        <GridSplitter Grid.Column="1" Width="5"  ResizeBehavior="PreviousAndNext" />

        <DataGrid 
            Grid.Column="2" 
            ItemsSource="{Binding SelectedFolders}" 
            AutoGenerateColumns="False"
            CanUserAddRows="False" CanUserDeleteRows="True" CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserResizeRows="False" CanUserSortColumns="True" 
            GridLinesVisibility="Horizontal" VerticalGridLinesBrush="Transparent" HorizontalGridLinesBrush="DarkGray"
            RowHeaderWidth="0"
            Background="Transparent" 
            BorderBrush="AliceBlue" BorderThickness="1">
            <DataGrid.CellStyle>
                <Style TargetType="{x:Type DataGridCell}">
                    <Setter Property="BorderBrush" Value="Transparent" />
                    <Setter Property="BorderThickness" Value="0" />
                </Style>
            </DataGrid.CellStyle>
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="Directory" Width="*" IsReadOnly="True" SortDirection="Ascending" SortMemberPath="Directory.FullName">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Directory.FullName, Mode=OneWay}" TextWrapping="Wrap" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="Recursive" SortMemberPath="Recursive">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding Recursive, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>

    </Grid>
</UserControl>
